﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infraestructure.CrossCutting.Parsering;
using System.Collections;
using System.IO;

namespace Infraestructure.CrossCutting.NetFramework.Parsering
{
    public class ParserTxtMonospaced: IParseBehavior
    {

        ArrayList _configuration;

        public ParserTxtMonospaced(ArrayList configuration)
        {
            this._configuration = configuration;
        }

        public List<System.Collections.ArrayList> Parse(string fileName)
        {
            List<ArrayList> list = new List<ArrayList>();

            if (!File.Exists(fileName))
            {
                throw new ArgumentException(string.Format(Resources.Messages.exception_InvalidPath, fileName));
            }

            using (StreamReader sr = new StreamReader(fileName))
            {
                String line;
                ArrayList element = new ArrayList();
                while ((line = sr.ReadLine()) != null)
                {
                    foreach (int item in _configuration)
                    {
                        string part = line.Substring(0, item);
                        line = line.Remove(0, item);
                        element.Add(part);
                    }
                    list.Add(element);
                }
            }

            return list;
        }
    }
}
